import type { GlobEnvConfig, GlobConfig, ProjectConfig } from '/@/types/config';
import { warn } from '/@/utils/log';
import { getGlobelEnvConfig, isDevMode } from '/@/utils/env';
import projectSetting from '/@/settings/projectSetting';
// TODO 这里可能有点问题
// const ENV = ((isDevMode()
//   ? getGlobEnvConfig()
//   : window[ENV_NAME as any]) as unknown) as GlobEnvConfig;

const ENV = getGlobelEnvConfig();
const reg = /[\w\_]*/;

const {
  VITE_GLOB_APP_TITLE,
  VITE_GLOB_API_URL,
  VITE_GLOB_APP_SHORT_NAME,
  VITE_GLOB_API_URL_PREFIX,
  VITE_GLOB_UPLOAD_URL,
} = ENV;

if (!reg.test(VITE_GLOB_APP_SHORT_NAME)) {
  warn('VITE_GLOB_APP_SHORT_NAME变量只能是字符/下划线，请修改环境变量后重新运行');
}
export const useGlobSetting = () => {
  const glob: Readonly<GlobConfig> = {
    // 网站标题
    title: VITE_GLOB_APP_TITLE,
    // 项目路径
    apiUrl: VITE_GLOB_API_URL,
    uploadUrl: VITE_GLOB_UPLOAD_URL,
    urlPrefix: VITE_GLOB_API_URL_PREFIX,
    shortName: VITE_GLOB_APP_SHORT_NAME,
  };
  return glob as Readonly<GlobConfig>;
};

export const useProjectSetting = (): ProjectConfig => {
  // TODO COMPUTED
  return projectSetting;
};
